#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        if (n == 1) return 1;
        vector<int> f(n, 1);
        vector<int> g(n, 1);
        int ret = 0;
        for (int i = 1;i < n;i++)
        {
            for (int j = i;j >= 0;j--)
            {
                if (nums[i] > nums[j]) f[i] = max(f[i], g[j] + 1);
                else if (nums[i] < nums[j]) g[i] = max(g[i], f[j] + 1);
            }
            ret = max(ret, max(f[i], g[i]));
        }
        return ret;
    }
};